<!doctype html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../../assert_selection.js"></script>
<script>
const isMac = navigator.platform.indexOf('Mac') === 0;
const kBehaviors = window.internals ? ['mac', 'win'] : isMac ? ['mac'] : ['win'];
for (const behavior of kBehaviors) {
  if (window.internals) {
    internals.settings.setEditingBehavior(behavior);
    internals.settings.setSelectTrailingWhitespaceEnabled(behavior !== 'mac');
  }

selection_test(
  '<div contenteditable dir="rtl">|Lorem <span dir="ltr">ipsum dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">^Lorem| <span dir="ltr">ipsum dolor sit</span> amet</div>'
      : '<div contenteditable dir="rtl">^Lorem |<span dir="ltr">ipsum dolor sit</span> amet</div>',
  `${behavior} 8-0 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">L|orem <span dir="ltr">ipsum dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">L^orem| <span dir="ltr">ipsum dolor sit</span> amet</div>'
      : '<div contenteditable dir="rtl">L^orem |<span dir="ltr">ipsum dolor sit</span> amet</div>',
  `${behavior} 8-1 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lo|rem <span dir="ltr">ipsum dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lo^rem| <span dir="ltr">ipsum dolor sit</span> amet</div>'
      : '<div contenteditable dir="rtl">Lo^rem |<span dir="ltr">ipsum dolor sit</span> amet</div>',
  `${behavior} 8-2 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lor|em <span dir="ltr">ipsum dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lor^em| <span dir="ltr">ipsum dolor sit</span> amet</div>'
      : '<div contenteditable dir="rtl">Lor^em |<span dir="ltr">ipsum dolor sit</span> amet</div>',
  `${behavior} 8-3 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lore|m <span dir="ltr">ipsum dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lore^m| <span dir="ltr">ipsum dolor sit</span> amet</div>'
      : '<div contenteditable dir="rtl">Lore^m |<span dir="ltr">ipsum dolor sit</span> amet</div>',
  `${behavior} 8-4 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem| <span dir="ltr">ipsum dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lorem^ <span dir="ltr">ipsum| dolor sit</span> amet</div>'
      : '<div contenteditable dir="rtl">Lorem^ |<span dir="ltr">ipsum dolor sit</span> amet</div>',
  `${behavior} 8-5 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span dir="ltr">|ipsum dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lorem <span dir="ltr">^ipsum| dolor sit</span> amet</div>'
      : '<div contenteditable dir="rtl">Lorem <span dir="ltr">^ipsum |dolor sit</span> amet</div>',
  `${behavior} 8-6 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span dir="ltr">i|psum dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lorem <span dir="ltr">i^psum| dolor sit</span> amet</div>'
      : '<div contenteditable dir="rtl">Lorem <span dir="ltr">i^psum |dolor sit</span> amet</div>',
  `${behavior} 8-7 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span dir="ltr">ip|sum dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lorem <span dir="ltr">ip^sum| dolor sit</span> amet</div>'
      : '<div contenteditable dir="rtl">Lorem <span dir="ltr">ip^sum |dolor sit</span> amet</div>',
  `${behavior} 8-8 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span dir="ltr">ips|um dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lorem <span dir="ltr">ips^um| dolor sit</span> amet</div>'
      : '<div contenteditable dir="rtl">Lorem <span dir="ltr">ips^um |dolor sit</span> amet</div>',
  `${behavior} 8-9 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsu|m dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsu^m| dolor sit</span> amet</div>'
      : '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsu^m |dolor sit</span> amet</div>',
  `${behavior} 8-10 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum| dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum^ dolor| sit</span> amet</div>'
      : '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum^ |dolor sit</span> amet</div>',
  `${behavior} 8-11 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum |dolor sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum ^dolor| sit</span> amet</div>'
      : '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum ^dolor |sit</span> amet</div>',
  `${behavior} 8-12 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum d|olor sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum d^olor| sit</span> amet</div>'
      : '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum d^olor |sit</span> amet</div>',
  `${behavior} 8-13 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum do|lor sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum do^lor| sit</span> amet</div>'
      : '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum do^lor |sit</span> amet</div>',
  `${behavior} 8-14 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum dol|or sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum dol^or| sit</span> amet</div>'
      : '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum dol^or |sit</span> amet</div>',
  `${behavior} 8-15 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum dolo|r sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum dolo^r| sit</span> amet</div>'
      : '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum dolo^r |sit</span> amet</div>',
  `${behavior} 8-16 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum dolor| sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum dolor^ sit|</span> amet</div>'
      : '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum dolor^ |sit</span> amet</div>',
  `${behavior} 8-17 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum dolor |sit</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum dolor ^sit|</span> amet</div>'
      : '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum dolor ^sit</span> |amet</div>',
  `${behavior} 8-18 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum dolor s|it</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum dolor s^it|</span> amet</div>'
      : '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum dolor s^it</span> |amet</div>',
  `${behavior} 8-19 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum dolor si|t</span> amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum dolor si^t|</span> amet</div>'
      : '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum dolor si^t</span> |amet</div>',
  `${behavior} 8-20 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum dolor sit</span>| amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  behavior === 'mac'
      ? '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum dolor sit</span>^ amet|</div>'
      : '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum dolor sit</span>^ |amet</div>',
  `${behavior} 8-21 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum dolor sit</span> |amet</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum dolor sit</span> ^amet|</div>',
  `${behavior} 8-22 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum dolor sit</span> a|met</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum dolor sit</span> a^met|</div>',
  `${behavior} 8-23 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum dolor sit</span> am|et</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum dolor sit</span> am^et|</div>',
  `${behavior} 8-24 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum dolor sit</span> ame|t</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum dolor sit</span> ame^t|</div>',
  `${behavior} 8-25 rtl left word`);

selection_test(
  '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum dolor sit</span> amet|</div>',
  selection => selection.modify('extend', 'left', 'word'),
  '<div contenteditable dir="rtl">Lorem <span dir="ltr">ipsum dolor sit</span> amet|</div>',
  `${behavior} 8-26 rtl left word`);
}
</script>
